package com.wang.springbootinit.controller.teacher;

import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.dto.AnswerCorrectRequest;
import com.wang.springbootinit.model.vo.AnswerRecordVO;
import com.wang.springbootinit.service.AnswerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 做题记录管理
 */
@RestController
@RequestMapping("/teacher/answer/record")
@Api(tags = "教师端-学生做题记录管理")
public class AnswerRecordController {

    @Autowired
    private AnswerRecordService answerRecordService;

    @GetMapping("/list")
    @ApiOperation("获取学生做题记录")
    public BaseResponse<List<AnswerRecordVO>> getStudentAnswerRecords(
            @RequestParam Long studentId,
            @RequestParam Long subjectId,
            @RequestParam(required = false) Long chapterId) {
        return ResultUtils.success(answerRecordService.getStudentAnswerRecords(studentId, subjectId, chapterId));
    }

    @PostMapping("/correct")
    @ApiOperation("批改学生题目")
    public BaseResponse<Boolean> correctStudentAnswer(@RequestBody AnswerCorrectRequest request) {
        return ResultUtils.success(answerRecordService.correctStudentAnswer(request.getRecordId(), request.getIsCorrect()));
    }
}
